package com.lxy.aimin.drug.controller;


import com.lxy.aimin.base.response.Result;
import com.lxy.aimin.drug.entity.TDrug;
import com.lxy.aimin.drug.service.TDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 药品表，用于存储具体药品的信息和库存状态 前端控制器
 * </p>
 *
 * @author lxy
 * @since 2025-07-01
 */
@RestController
@RequestMapping("/drug")
public class TDrugController {

    @Autowired
    private TDrugService tDrugService;

    @RequestMapping("/list")
    public Result<?> list() {
        List<TDrug> list = tDrugService.list();
        return Result.success(list);
    }


    @RequestMapping("/{id}")
    public Result<?> getById(@PathVariable("id") Integer id) {
        TDrug tDrug = tDrugService.getById(id);
        return Result.success(tDrug);
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable("id") Integer id) {
        boolean b = tDrugService.removeById(id);
        return b ? Result.success() : Result.error("删除失败");
    }

}
